import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

/// 扩展 Widget
extension ExWidget on Widget {
  /// 手势
  Widget onTap(
    GestureTapCallback? onTap, {
    Key? key,
    HitTestBehavior? behavior,
    bool excludeFromSemantics = false,
    DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  }) => GestureDetector(
    key: key,
    onTap: onTap,
    behavior: behavior ?? HitTestBehavior.opaque,
    excludeFromSemantics: excludeFromSemantics,
    dragStartBehavior: dragStartBehavior,
    child: this,
  );

  /// 长按手势
  Widget onLongPress(
    GestureTapCallback? onLongPress, {
    Key? key,
    HitTestBehavior? behavior,
    bool excludeFromSemantics = false,
    DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  }) => GestureDetector(
    key: key,
    onLongPress: onLongPress,
    behavior: behavior ?? HitTestBehavior.opaque,
    excludeFromSemantics: excludeFromSemantics,
    dragStartBehavior: dragStartBehavior,
    child: this,
  );

  /// 约束 高度
  Widget height(double height, {Key? key}) => ConstrainedBox(
    key: key,
    constraints: BoxConstraints.tightFor(height: height),
    child: this,
  );

  /// 约束 宽度
  Widget width(double width, {Key? key}) => ConstrainedBox(
    key: key,
    constraints: BoxConstraints.tightFor(width: width),
    child: this,
  );
}
